package com.wytec.xywzxw.configuration;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;

@Configuration
public class RedisConfiguration {
    /**
     * @author wei
     */
    @Value("${spring.data.redis.host}")
    private String host;
    @Value("${spring.data.redis.port}")
    private int port;
    @Value("${spring.data.redis.timeout}")
    private int timeout;
    @Value("${spring.data.redis.database}")
    private int database;
    @Value("${spring.data.redis.password}")
    private String password;

    @Bean
    public JedisPool jedisPool() {
        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
        JedisPool jedisPool;
        jedisPool = new JedisPool(config, host, port, timeout, password);
        jedisPool.getResource().select(database);
        return jedisPool;
    }
}
